package com.dayi.utils;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dayi.R;
import com.dayi.utils.pop.AnswerQuestionPopupUtils;
import com.zyyoona7.popup.EasyPopup;

import androidx.appcompat.widget.AppCompatEditText;
import androidx.cardview.widget.CardView;


/**
 * 学生举报老师窗口
 */
public class ReportTeacherPopupUtils {

    private Activity activity;

    public ReportTeacherPopupUtils(Activity ac) {

        this.activity = ac;

        initReportPopuPopu();
    }

    private EasyPopup answerPopu;

    private void initReportPopuPopu() {
        answerPopu = EasyPopup.create()
                .setContext(activity)
                .setContentView(R.layout.popup_reportteacher)

                .setWidth(WindowManager.LayoutParams.FILL_PARENT)

                .setHeight(WindowManager.LayoutParams.FILL_PARENT)

                .setOnViewListener(new EasyPopup.OnViewListener() {
                    @Override
                    public void initViews(View view, EasyPopup basePopup) {

                        initView(view);


                    }


                })
                .setFocusAndOutsideEnable(true)
                .apply();

    }

    private AppCompatEditText et_reason;

    private LinearLayout lin_report;

    private ImageView iv_hide;

    private CardView card;

    private TextView tv_title;


    private void initView(View view) {

        card = view.findViewById(R.id.card);
        et_reason = view.findViewById(R.id.et_reason);
        iv_hide = view.findViewById(R.id.iv_hide);

        lin_report = view.findViewById(R.id.lin_report);

        card.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        iv_hide.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                answerPopu.dismiss();
            }
        });


        lin_report.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String text = et_reason.getText().toString().trim();
                if (text.equals("")) {
                    Toast.makeText(activity, "内容不能为空", Toast.LENGTH_SHORT).show();
                }

                if (listener != null) {
                    listener.onSure(text);
                }

                answerPopu.dismiss();


            }
        });

    }

    public void showAnswerPopuPopu(View view) {

        answerPopu.showAtLocation(view, Gravity.CENTER, 0, 0);
    }


    private AnswerQuestionPopupUtils.AnswerQuestionPopupUtilsListener listener;

    public void setAnswerQuestionPopupUtilsListener(AnswerQuestionPopupUtils.AnswerQuestionPopupUtilsListener answerQuestionPopupUtilsListener) {

        this.listener = answerQuestionPopupUtilsListener;

    }

    public void dismiss() {
        answerPopu.dismiss();
    }

    public interface AnswerQuestionPopupUtilsListener {

        void onSure(String content);


    }

}
